home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Environment Additions / Symantec / Additions / SOM (SPM) / somcdev.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-27  |  7.3 KB  |  248 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3. Created: Friday, March 24, 1995 at 3:44:21 PM
  4.     somcdev.h
  5.     
  6.     System Object Model macro definitions
  7.     Macintosh Version
  8.  
  9.         © International Business Machines Corp. 1992-1994
  10.         © Apple Computer, Inc.                    1994-1995
  11.         All rights reserved
  12.  
  13. ************************************************************/
  14.  
  15.  
  16. #ifndef        __SOMCDEV__
  17. #define        __SOMCDEV__
  18.  
  19. /*
  20.  *  Method and Data Resolution macros
  21.  */
  22.  
  23. /*
  24.  *  Method Resolution. Methods are invoked on an object o of some
  25.  *  object class oc, where oc has immediate ancestor classes
  26.  *  called parent classes. Macro arguments include method names
  27.  *  (e.g., mn), object class and parent class names (e.g., ocn, pcn)
  28.  *  and parent class positions (e.g., pcp), expressed in terms of the
  29.  *  left-to-right ordering (beginning with 1, for the first parent)
  30.  *  used when declaring oc's parents. The choice of resolution
  31.  *  macro determines the method table from which methods are selected.
  32.  *
  33.  *  Macros are available to select a method from ...
  34.  */
  35.  
  36. /*
  37.  * Default definition of somresolve_ to call the procedure, somResolve.
  38.  * This may be be changed by emitters on systems for which method
  39.  * tokens are thunks.
  40.  */
  41. #define somresolve_(obj,mToken) (somResolve(obj,mToken))
  42.  
  43. /* from oc's mtbl, with verification of o */
  44. #define SOM_Resolve(o, ocn, mn) \
  45.     (( somTD_ ## ocn ## _ ## mn ) \
  46.      somresolve_(SOM_TestCls_TT(o, ocn), \
  47.                 ocn ## ClassData.mn ))
  48.  
  49. /* from oc's mtbl, without verification of o */
  50. #define SOM_ResolveNoCheck(o, ocn, mn) \
  51.     (( somTD_ ## ocn ## _ ## mn ) \
  52.      somresolve_(o, \
  53.                 ocn ## ClassData.mn ))
  54.  
  55. /* from the pcp'th element of oc's ClassData.parentMtab list */
  56. #define SOM_ParentNumResolveCC(pcn, pcp, ocn, mn) \
  57.     (( somTD_ ## pcn ## _ ## mn ) \
  58.      somParentNumResolve( (somClassDataStructure*) & ocn ## ClassData, pcp, \
  59.                          pcn ## ClassData.mn ))
  60.  
  61. /* from an argument class's method table */
  62. #define SOM_ClassResolve(cn, class, mn) \
  63.     (( somTD_ ## cn ## _ ## mn ) \
  64.      somClassResolve(class, \
  65.                      cn ## ClassData.mn ))
  66.  
  67.  
  68. /* support reintroduction of methods */
  69. /* tdc == typedef class name; cdc == classdata class name */
  70. #define SOM_ResolveD(o, tdc, cdc, mn) \
  71.     (( somTD_ ## tdc ## _ ## mn ) \
  72.       somresolve_(SOM_TestCls_TT(o, cdc),\
  73.                  cdc ## ClassData.mn))
  74.  
  75. /*
  76.  * Data resolution macro
  77.  */
  78.  
  79. #define SOM_DataResolve(obj, dataId) \
  80.   (somDataResolve(obj, dataId))
  81.  
  82.  
  83. #if !defined(__SOMDLL__)
  84.  
  85.   /*
  86.    * Main programs should register for SOM cleanup at exit
  87.    */
  88.  
  89.    #define SOM_MainProgram()\
  90.     (atexit(somEnvironmentEnd), somMainProgram())
  91.  
  92.   /*
  93.    * somEnvironmentEnd may not have the right
  94.    * linkage to be called by atexit. Allow a user to
  95.    * create a routine that can be called by atexit
  96.    * and which will call somEnvironmentEnd.
  97.    */
  98.  
  99.    #define SOM_MainProgramWithUserExit( userExitFcn ) \
  100.     (atexit( userExitFcn ), somMainProgram())
  101.  
  102. #endif /* __SOMDLL__ */
  103.  
  104. /*
  105.  * Platform provided automatic class library initialization rtns
  106.  * should use this macro to inform the SOM Class Manager that
  107.  * they have been loaded. 
  108.  */
  109. #define SOM_ClassLibrary(name)\
  110.     (somRegisterClassLibrary(name,\
  111.         (somMethodProc *) &SOMInitModule))
  112.  
  113.  
  114. /*
  115.  *   Development support macros and globals
  116.  */
  117.  
  118. #ifdef SOM_STRICT_IDL
  119. #define SOMSTAR
  120. #else
  121. #define SOMSTAR *
  122. #endif
  123.  
  124. /*
  125.  * This macro is used throughout the generated source
  126.  * to prevent compiler warnings for unreferenced variables
  127.  */
  128. #ifndef SOM_IgnoreWarning
  129.     #ifdef __xlC__
  130.     #define SOM_IgnoreWarning(v)    
  131.     #else
  132.     #define SOM_IgnoreWarning(v)    (void) v
  133.     #endif
  134. #endif /* SOM_IgnoreWarning */
  135.  
  136. /* Check the validity of method resolution using the specified target  */
  137. /* object.  Note: this macro makes programs bigger and slower.  After  */
  138. /* you are confident that your program is running correctly you should */
  139. /* turn off this macro by defining SOM_NoTest, or adding -DSOM_NoTest  */
  140. /* to your makefile.                                                   */
  141.  
  142. #if !defined(SOM_NoTest) && defined(SOM_TestOn)
  143.   #define SOM_TestCls(obj, class) (somTestCls(((SOMObject SOMSTAR)\
  144.     ((void *)obj)), ((SOMClass SOMSTAR)((void *)class)), __FILE__, __LINE__))
  145.   #define SOM_Measure
  146. #else
  147.   #define SOM_TestCls(obj, class) ((SOMObject SOMSTAR)((void *)obj))
  148. #endif
  149.  
  150. #if !defined(SOM_NoTest) && defined(SOM_TestOn)
  151.   #define SOM_TestCls_TT(obj, class) (somTestClsTT(((SOMObject SOMSTAR)\
  152.     ((void *)obj)),  (somClassDataStructure*)&(class ## ClassData)), __FILE__, __LINE__))
  153.   #define SOM_Measure
  154. #else
  155.   #define SOM_TestCls_TT(obj, class) ((SOMObject SOMSTAR)((void *)obj))
  156. #endif
  157.  
  158. /* Control the printing of method and procedure entry messages, */
  159. /* 0-none, 1-user, 2-core&user */
  160. SOMEXTERN int SOMDLINK SOM_TraceLevel;
  161.  
  162. /* Control the printing of warning messages, 0-none, 1-all */
  163. SOMEXTERN int SOMDLINK SOM_WarnLevel;
  164.  
  165. /* Control the printing of successful assertions, 0-none, 1-user, */
  166. /* 2-core&user */
  167. SOMEXTERN int SOMDLINK SOM_AssertLevel;
  168.  
  169. /*
  170.  *  Scans argv looking for flags -somt, -somtc, -soma -somac -somw setting
  171.  *  SOM_TraceLevel, SOM_AssertLevel and SOM_WarnLevel as appropriate.
  172.  *  argv is not modified
  173.  */
  174. SOMEXTERN void SOMLINK somCheckArgs(int argc, char *argv[]);
  175.  
  176. #define SOM_Error(c) ((*SOMError) (c,__FILE__, __LINE__))
  177.  
  178. #define SOM_NoTrace(c,m)
  179.  
  180. #ifdef _RETAIL
  181.   #define SOM_Trace(c,m)
  182.   #define SOM_TraceCore(c,m)
  183. #else
  184.   #define SOM_Trace(c,m) if (SOM_TraceLevel > 0) \
  185.       somPrintf("\"%s\": %d:\tIn %s:%s \n", \
  186.           __FILE__, __LINE__, c, m)
  187.  
  188.   #define SOM_TraceCore(c,m) if (SOM_TraceLevel > 1) \
  189.       somPrintf("\"%s\": %d:\tIn %s:%s \n", \
  190.           __FILE__, __LINE__, c, m)
  191. #endif
  192.  
  193. SOMEXTERN void SOMLINK somTest(int condition, int severity,
  194.     corbastring fileName, int lineNum, corbastring msg);
  195.  
  196. #define SOM_Assert(condition,ecode) \
  197.   (somAssert(condition, ecode, __FILE__, __LINE__, # condition))
  198.  
  199. #define SOM_AssertCore(condition,ecode) \
  200.   (somAssertCore(condition, ecode, __FILE__, __LINE__, # condition))
  201.  
  202. #define SOM_Expect(condition) \
  203.       somTest(condition, SOM_Warn, __FILE__, __LINE__, # condition)
  204.  
  205. #define SOM_WarnMsg(msg) \
  206.   if (SOM_WarnLevel > 0) \
  207.       somPrintf("\"%s\": %d:\tWarning: %s\n", __FILE__, __LINE__, msg)
  208.  
  209. #define SOM_Test(boolexp) \
  210.     somTest(boolexp, SOM_Fatal, __FILE__, __LINE__, # boolexp)
  211.  
  212. #define SOM_TestC(boolexp) \
  213.     somTest(boolexp, SOM_Warn, __FILE__, __LINE__, # boolexp)
  214.  
  215. /*
  216.  *   Default method debug macro, can be overridden
  217.  */
  218. #ifndef SOMMethodDebug
  219. #define SOMMethodDebug(c,m) SOM_Trace(c,m)
  220. #endif
  221.  
  222. #ifndef SOMProcedureDebug
  223. #define SOMProcedureDebug(c,m) SOM_Trace(c,m)
  224. #endif
  225.  
  226. /*
  227.  *  Error severity codes, these are added to the base error number to
  228.  *  produce the full error code
  229.  */
  230.  
  231. #define SOM_Ok        0x0
  232. #define SOM_Warn      0x1
  233. #define SOM_Ignore    0x2 /* don't do anything */
  234. #define SOM_Fatal     0x9 /* terminate the program */
  235. #define SOM_Template  0x5 /* use to identify msg templates */
  236.  
  237. #define SOM_EB 20000
  238. #define SOM_FatalCode(code) (SOM_EB + (code)*10 + SOM_Fatal)
  239. #define SOM_WarnCode(code) (SOM_EB + (code)*10 + SOM_Warn)
  240. #define SOM_IgnoreCode(code) (SOM_EB + (code)*10 + SOM_Ignore)
  241. #define SOM_OkCode(code) (SOM_EB + (code)*10 + SOM_Ok)
  242. #define SOM_TemplateCode(code) (SOM_EB + (code)*10 + SOM_Template)
  243. #define SOM_MsgCode(ecode) (((ecode)-SOM_EB)/10)
  244.  
  245. #define SOMERROR_MustOverride SOM_FatalCode(18)
  246.  
  247. #endif    /* __SOMCDEV__ */
  248.